package com.fuqi.android.zhongcai.base.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.Constants;
import com.fuqi.android.zhongcai.base.mvp.presenter.AboutPresenterImpl;
import com.fuqi.android.zhongcai.base.mvp.presenter.AboutPresenterInter;
import com.fuqi.android.zhongcai.base.mvp.view.IAboutView;
import com.fuqi.android.zhongcai.base.view.activity.deprecated.WebDocActivity;
import com.fuqi.android.zhongcai.utils.ActivityUtils;
import com.fuqi.android.zhongcai.utils.VersionUtils;

import butterknife.Bind;
import butterknife.OnClick;

public class AboutActivity extends BaseActivity implements IAboutView {

    @Bind(R.id.about_app_version)
    TextView versionName;
    AboutPresenterInter aboutPresenter;


    @OnClick({R.id.tv_about_service, R.id.tv_about_version_update, R.id.tv_about_contact})
    public void onClickListener(View view) {

        switch (view.getId()) {

            case R.id.tv_about_service:
                Bundle bundle = new Bundle();
                bundle.putString("url", "file:///android_asset/html/user_protocol.html");
                bundle.putString("title", "服务条款");
                ActivityUtils.startActivity(getApplicationContext(), WebDocActivity.class, bundle);
                break;

            case R.id.tv_about_version_update:
                aboutPresenter.checkNewVersion();
                break;

            case R.id.tv_about_contact:
                ActivityUtils.callTo(getApplicationContext(), Constants.CONTCAT_US_PHONE_NUMBER);
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }



    private void initViews() {

        versionName.setText("版本号:  V" + VersionUtils.getVersionName());

    }


    @Override
    public void hasNewVersion() {
        ActivityUtils.toast("开始下载最新版本...");
        aboutPresenter.startUpdateVersion();
    }

    @Override
    public void noNewVersion() {
        ActivityUtils.toast("当前已是最新版本");
    }

    @Override
    public void checkNewVersionFailed() {
        ActivityUtils.toast("check new version failed");
    }


    @Override
    public void initView() {
        initViews();
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
        titleBar.setTitle("关于");
        aboutPresenter = new AboutPresenterImpl(this);
    }

    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_about;
    }
}
